package cn.ibobo.lease.common.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Description: Spring上下文管理工具类 <br/> 
 * Project: meiduoduo-common <br/>
 * ClassName: SpringContextUtil <br/>
 * Copyright: Copyright (c) 2017 deshang <br/>
 * @author ZHENG.Q <br/>
 * @version 2.0 2018年2月25日下午4:24:28 <br/>
 */
@Component
public class SpringContextUtil implements ApplicationContextAware {

	private ApplicationContext applicationContext = null;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		if (this.applicationContext == null) {
			this.applicationContext = applicationContext;
		}

	}

	public ApplicationContext getApplicationContext() {
		return this.applicationContext;
	}

	public Object getBean(String name) {
		return getApplicationContext().getBean(name);
	}

	public <T> T getBean(Class<T> clazz) {
		return getApplicationContext().getBean(clazz);
	}

}
